home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / curve / menu.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  9KB  |  379 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *
  19.  * menu.c
  20.  *
  21.  * Part of the "Curve Demo"
  22.  * by Howard Look for Silicon Graphics
  23.  *
  24.  * June, 1989
  25.  *
  26.  * This file contains the routines used for initializing and
  27.  * maintaining the menus that make up the curve demo.
  28.  *
  29.  */
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <gl.h>
  34. #include <device.h>
  35. #include <math.h>
  36. #include "event.h"
  37. #include "curve.h"
  38.  
  39.  
  40. /* Prototypes */
  41. void init_menus(void);
  42. void do_menus(void);
  43. void remake_curve_menu(void);
  44. void remake_basis_menu(void);
  45. void remake_display_menu(void);
  46. void remake_precision_menu(void);
  47. void remake_speed_menu(void);
  48. void remake_style_menu(void);
  49. void remake_options_menu(void);
  50. void remake_whizbang_menu(void);
  51. void remake_all_menus(void);
  52.  
  53. extern void set_defaults(void);
  54. extern void change_display(int);
  55. extern void toggle_markers(void);
  56. extern void toggle_hulls(void);
  57. extern void toggle_motion(void);
  58. extern void toggle_smear(void);
  59. extern void change_basis(int);
  60. extern void change_precision(int);
  61. extern void change_speed(int);
  62. extern void change_style(int);
  63. extern void change_whizbang(int);
  64. extern void quit(void);
  65. extern void clear_window(void);
  66. extern void help(void);
  67. extern void end_help(void);
  68.  
  69.  
  70. /* Declare menus */
  71. static long curve_menu;        /* Top level Menu */
  72. static long basis_menu;        /* Curve Basis - Bezier, Cardinal, B-Spline */
  73. static long display_menu;    /* 2D or 3D display */
  74. static long options_menu;    /* Program options */
  75. static long precision_menu; /* Sub-options menu : Spline precision */
  76. static long speed_menu;        /* Sub-options menu : Motion speed factor */
  77. static long style_menu;        /* Sub-options menu: Line style */
  78. static long whizbang_menu;    /* Sub-options menu: Whizbang demos */
  79.  
  80.  
  81. /* Environment variables */
  82. extern 
  83. int        curve_basis, 
  84.         display_mode, 
  85.         curve_precision,
  86.         speed, 
  87.         line_style, 
  88.         whizbang;
  89. extern
  90. Boolean    markers,
  91.         hulls,
  92.         motion, 
  93.         smear;
  94.  
  95.  
  96. /* 
  97.  * Allocate and initialize the menus, then tell the event manager
  98.  * to watch for right mouse button clicks.
  99.  */
  100. void init_menus(void)
  101. {
  102.     curve_menu = newpup();
  103.     basis_menu = newpup();
  104.     display_menu = newpup();
  105.     precision_menu = newpup();
  106.     speed_menu = newpup();
  107.     style_menu = newpup();
  108.     whizbang_menu = newpup();
  109.     options_menu = newpup();
  110.  
  111.     set_initial_conditions();
  112.     remake_all_menus();
  113.     
  114.     add_event(ANY,  RIGHTMOUSE, DOWN, do_menus, NULL);
  115.     qdevice(RIGHTMOUSE);
  116. }
  117.  
  118.  
  119. /*
  120.  * Called by the event manager whenever the right mouse button is
  121.  * pressed.
  122.  */
  123. void do_menus(void)
  124. {
  125.     end_help();
  126.     dopup(curve_menu);
  127. }
  128.  
  129.  
  130. /*
  131.  * Rebuild the entire menu tree. Because menu items change based upon
  132.  * user input, sub-menus are rebuilt as necessary. Then the root menu
  133.  * is rebuilt using these chaned sub-menus.
  134.  */
  135. void remake_curve_menu(void)
  136. {
  137.     freepup(curve_menu);
  138.     curve_menu = newpup();
  139.  
  140.     addtopup(curve_menu, "Curve %t"); /* title */
  141.     addtopup(curve_menu, "Curve Basis %m", basis_menu);
  142.     addtopup(curve_menu, "Display Mode %m", display_menu);
  143.     addtopup(curve_menu, "Options %m", options_menu);
  144.     addtopup(curve_menu, "Set Defaults %f", set_defaults);
  145.     addtopup(curve_menu, "Clear Window %f", clear_window);
  146.     addtopup(curve_menu, "Help %f", help);
  147.     addtopup(curve_menu, "Quit Curve %f", quit);
  148. }
  149.  
  150.  
  151. /*
  152.  * Remakes the menu which giving control over the curve basis
  153.  * matrix.
  154.  */
  155. void remake_basis_menu(void)
  156. {
  157.     char menu_string[32];
  158.     
  159.     freepup(basis_menu);
  160.     basis_menu = newpup();
  161.  
  162.     addtopup(basis_menu, "Curve Basis %t %F", change_basis);
  163.     
  164.     if (curve_basis == BEZIER)
  165.         sprintf(menu_string, "->Bezier Spline %%x%d", BEZIER);
  166.     else
  167.         sprintf(menu_string, "  Bezier Spline %%x%d", BEZIER);
  168.     addtopup(basis_menu, menu_string);
  169.  
  170.     if (curve_basis == CARDINAL)
  171.         sprintf(menu_string, "->Cardinal Spline %%x%d", CARDINAL);
  172.     else
  173.         sprintf(menu_string, "  Cardinal Spline %%x%d", CARDINAL);
  174.     addtopup(basis_menu, menu_string);
  175.  
  176.     if (curve_basis == BSPLINE)
  177.         sprintf(menu_string, "->B-Spline %%x%d", BSPLINE);
  178.     else
  179.         sprintf(menu_string, "  B-Spline %%x%d", BSPLINE);
  180.     addtopup(basis_menu, menu_string);
  181. }
  182.  
  183.  
  184. /* Remake the menu giving control over the display mode, i.e. two
  185.  * dimensional or three dimensional.
  186.  */
  187. void remake_display_menu(void)
  188. {
  189.     char menu_string[32];
  190.     
  191.     freepup(display_menu);
  192.     display_menu = newpup();
  193.  
  194.     addtopup(display_menu, "Display Mode %t %F", change_display);
  195.  
  196.     if (display_mode == TWO_D)
  197.         sprintf(menu_string, "->Two Dimensional %%x%d", TWO_D);
  198.     else
  199.         sprintf(menu_string, "  Two Dimensional %%x%d", TWO_D);
  200.     addtopup(display_menu, menu_string);
  201.     
  202.     if (display_mode == THREE_D)
  203.         sprintf(menu_string, "->Three Dimensional %%x%d", THREE_D);
  204.     else
  205.         sprintf(menu_string, "  Three Dimensional %%x%d", THREE_D);
  206.     addtopup(display_menu, menu_string);
  207. }
  208.  
  209.  
  210. /* Remake the menu giving control over the precision over spline
  211.  * segments. MIN_PRECISION, MAX_PRECISION and PRECISION_STEP may
  212.  * be changed in curve.h, though they should reflect reasonable
  213.  * integer values.
  214.  */
  215. void remake_precision_menu(void)
  216. {
  217.     char menu_string[16];
  218.     int i;
  219.     
  220.     freepup(precision_menu);
  221.     precision_menu = newpup();
  222.  
  223.     addtopup(precision_menu, "Segments per Spline %t %F",
  224.     change_precision);
  225.  
  226.     for (i = MIN_PRECISION; i<=MAX_PRECISION; i+=PRECISION_STEP)
  227.     {
  228.         if (curve_precision == i)
  229.         {
  230.             sprintf(menu_string, "->%d %%x%d", i, i);
  231.             addtopup(precision_menu, menu_string);
  232.         }
  233.         else
  234.         {
  235.             sprintf(menu_string, "  %d %%x%d", i, i);
  236.             addtopup(precision_menu, menu_string);
  237.         }
  238.     }
  239. }
  240.  
  241.  
  242. /* Remakes the menu giving control over the speed of motion, when
  243.  * active. Speed is increased by simply multiplying the motion offset
  244.  * for each control point by this speed constant. MIN_SPEED, MAX_SPEED
  245.  * and SPEED_STEP may be changed in curve.h, but should reflect
  246.  * reasonable integer values.
  247.  */
  248. void remake_speed_menu(void)
  249. {
  250.     char menu_string[16];
  251.     int i;
  252.     
  253.     freepup(speed_menu);
  254.     speed_menu = newpup();
  255.  
  256.     addtopup(speed_menu, "Motion Speed %t %F", change_speed);
  257.  
  258.     for (i = MIN_SPEED; i<=MAX_SPEED; i+=SPEED_STEP)
  259.     {
  260.         if (speed == i)
  261.         {
  262.             sprintf(menu_string, "->%d %%x%d", i, i);
  263.             addtopup(speed_menu, menu_string);
  264.         }
  265.         else
  266.         {
  267.             sprintf(menu_string, "  %d %%x%d", i, i);
  268.             addtopup(speed_menu, menu_string);
  269.         }
  270.     }
  271. }
  272.  
  273.  
  274. /* Remakes the menu giving control over line style used to draw the
  275.  * curves. The patterns are defined in curve.h, and may be changed.
  276.  */
  277. void remake_style_menu(void)
  278. {
  279.     char menu_string[32];
  280.     
  281.     freepup(style_menu);
  282.     style_menu = newpup();
  283.  
  284.     addtopup(style_menu, "Line Style %t %F", change_style);
  285.  
  286.     if (line_style == SOLID)
  287.         sprintf(menu_string, "->Solid %%x%d", SOLID);
  288.     else
  289.         sprintf(menu_string, "  Solid %%x%d", SOLID);
  290.     addtopup(style_menu, menu_string);
  291.  
  292.     if (line_style == DOTTED)
  293.         sprintf(menu_string, "->Dotted %%x%d", DOTTED);
  294.     else
  295.         sprintf(menu_string, "  Dotted %%x%d", DOTTED);
  296.     addtopup(style_menu, menu_string);
  297.  
  298.     if (line_style == DASHED)
  299.         sprintf(menu_string, "->Dashed %%x%d", DASHED);
  300.     else
  301.         sprintf(menu_string, "  Dashed %%x%d", DASHED);
  302.     addtopup(style_menu, menu_string);
  303. }
  304.  
  305.  
  306. void remake_whizbang_menu(void)
  307. {
  308.     char menu_string[32];
  309.  
  310.     freepup(whizbang_menu);
  311.     whizbang_menu = newpup();
  312.  
  313.     addtopup(whizbang_menu, "Whizbangs %t %F", change_whizbang);
  314.  
  315.     sprintf(menu_string, "Coil %%x%d", COIL);
  316.     addtopup(whizbang_menu, menu_string);
  317.  
  318.     sprintf(menu_string, "Bed Spring %%x%d", BEDSPRING);
  319.     addtopup(whizbang_menu, menu_string);
  320.  
  321.     sprintf(menu_string, "Doughnut %%x%d", DOUGHNUT);
  322.     addtopup(whizbang_menu, menu_string);
  323. }
  324.  
  325. /* Remakes the options menu, which includes some of the above menus as
  326.  * sub-menus and is itself a sub-menu to the root menu.
  327.  */
  328. void remake_options_menu(void)
  329. {
  330.     freepup(options_menu);
  331.     options_menu = newpup();
  332.  
  333.     addtopup(options_menu, "Options %t");
  334.  
  335.     if (motion == ON)
  336.         addtopup(options_menu, "Turn Motion Off %f",
  337.         toggle_motion);
  338.     else
  339.         addtopup(options_menu, "Turn Motion On %f", toggle_motion);
  340.  
  341.     if (markers == ON)
  342.         addtopup(options_menu, "Turn Markers Off %f",
  343.         toggle_markers);
  344.     else
  345.         addtopup(options_menu, "Turn Markers On %f", toggle_markers);
  346.  
  347.     if (hulls == ON)
  348.         addtopup(options_menu, "Turn Hulls Off %f",
  349.         toggle_hulls);
  350.     else
  351.         addtopup(options_menu, "Turn Hulls On %f", toggle_hulls);
  352.  
  353.     if (smear == ON)
  354.         addtopup(options_menu, "Turn Smear Off %f",
  355.         toggle_smear);
  356.     else
  357.         addtopup(options_menu, "Turn Smear On %f", toggle_smear);
  358.  
  359.     addtopup(options_menu, "Precision %m", precision_menu);
  360.  
  361.     addtopup(options_menu, "Speed %m", speed_menu);
  362.  
  363.     addtopup(options_menu, "Line Style %m",  style_menu);
  364.  
  365.     addtopup(options_menu, "Whizbangs %m",  whizbang_menu);
  366. }
  367.  
  368. void remake_all_menus()
  369. {
  370.     remake_basis_menu();
  371.     remake_display_menu();
  372.     remake_precision_menu();
  373.     remake_speed_menu();
  374.     remake_style_menu();
  375.     remake_whizbang_menu();
  376.     remake_options_menu();
  377.     remake_curve_menu();
  378. }
  379.